package com.bjmashibing.system.OSFileIO.io_demo.anotherStream;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 和之前的reader不同的是，直接从字节数组中读取数据，另外，还可以进行跳跃读取
 */
public class ByteArrayInputStreamDemo {

    public static void main(String[] args) throws IOException {
        demo1();
    }


    public static void demo1() throws IOException {

        String str="david";

        byte[] buffer = str.getBytes(StandardCharsets.UTF_8);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer);

        int length=0;
        while ((length=byteArrayInputStream.read())!=-1){
            byteArrayInputStream.skip(2);//按照n个进行跳跃
            System.out.println((char) length);
        }
        byteArrayInputStream.close();
    }

}
